package com.jh.paymentchannel.business.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;

import com.jh.paymentchannel.pojo.Spend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jh.paymentchannel.business.SpendBusiness;
import com.jh.paymentchannel.repository.SpendRepository;
@Service
public class SpendBusinessImpl implements SpendBusiness {

	@Autowired
	private SpendRepository spendRepository;
	@Autowired
	private EntityManager em;
	@Override
	@Transactional
	public Spend addOne(Spend model) {
		Spend spend = spendRepository.save(model);
		em.flush();
		em.clear();
		return spend;
	}

	@Override
	public List<Spend> findByOrderCode(String orderCode) {
		return spendRepository.findByOrderCode(orderCode);
	}

	@Override
	@Transactional
	public Spend save(Spend model) {
		Spend spend = spendRepository.save(model);
		em.flush();
		em.clear();
		return spend;
	}

	@Override
	public Spend findByOrderCodeAndAmount(String orderCode, String amount) {
		return spendRepository.findByOrderCodeAndAmount(orderCode,amount);
	}

	@Override
	public List<Spend> findByExecutionTime(String start, String end) {
		// TODO Auto-generated method stub
		return spendRepository.findByExecutionTime(start, end);
	}

	@Override
	public void delete(Spend spend) {
		// TODO Auto-generated method stub
		spendRepository.delete(spend);
		em.clear();
	}

	@Override
	public Spend findByorderSon(String orderSon) {
		// TODO Auto-generated method stub
		return spendRepository.findByorderSon(orderSon);
	}

	@Override
	public List<Spend> findByExecutionTimeandStatus(String start, String end) {
		// TODO Auto-generated method stub
		return spendRepository.findByExecutionTimeandStatus(start, end);
	}

	@Override
	public List<Spend> findByUserId(String userId) {
		// TODO Auto-generated method stub
		return spendRepository.findByUserId(userId);
	}

	@Override
	public Spend findById(long id) {
		// TODO Auto-generated method stub
		return spendRepository.findById(id);
	}

	@Override
	public List<Spend> queryTaskByBatchNo(String batchNo) {
		List<Spend> task = new ArrayList<Spend>();
		task = spendRepository.findTaskByBatchNo(batchNo);
		return task;
	}

	@Override
	public List<Spend> findBybindId(String bindId) {
		// TODO Auto-generated method stub
		return spendRepository.findBybindId(bindId);
	}

}
